﻿Imports System.Data
Imports System.Data.OleDb
Imports System.Xml
Imports System
Public Class rss
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Response.Clear()
        Response.ContentType = "text/xml"
        Dim Xml_Text As New XmlTextWriter(Response.OutputStream, Encoding.UTF8)
        Xml_Text.WriteStartDocument()
        Xml_Text.WriteStartElement("rss")
        Xml_Text.WriteAttributeString("version", "2.0")
        Xml_Text.WriteStartElement("channel")
        Xml_Text.WriteElementString("title", "Old Universities")
        Xml_Text.WriteElementString("link", "Default.aspx")
        Xml_Text.WriteElementString("description", "This is site for the list of old universities")
        Xml_Text.WriteElementString("ttl", "5")

        Dim DBconn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("UniConnectionString").ConnectionString)
        DBconn.Open()

        Dim Query As String = "select ID, Uni_Name, Description from Universities"
        Dim DBCmd As OleDbCommand = New OleDbCommand(Query, DBconn)
        Dim DBreader As OleDbDataReader = DBCmd.ExecuteReader()
        While (DBreader.Read())
            Xml_Text.WriteStartElement("item")
            Xml_Text.WriteElementString("title", DBreader("Uni_Name"))
            Xml_Text.WriteElementString("description", DBreader("Description"))
            Xml_Text.WriteElementString("link", "Details.aspx?ID=" + DBreader("ID").ToString())
            Xml_Text.WriteEndElement()

        End While
        DBreader.Close()
        DBconn.Close()

        Xml_Text.WriteEndElement()
        Xml_Text.WriteEndElement()
        Xml_Text.WriteEndDocument()
        Xml_Text.Flush()
        Xml_Text.Close()
        Response.End()
    End Sub

End Class